package com.zzy.app.config.importannotation;

import com.zzy.app.entity.Rainbow;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar{
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean redBean = registry.containsBeanDefinition("com.zzy.app.entity.Red");
        boolean blueBean = registry.containsBeanDefinition("com.zzy.app.entity.Blue");
        if(redBean && blueBean){
            RootBeanDefinition rainbowBean = new RootBeanDefinition(Rainbow.class);
            registry.registerBeanDefinition("rainbow", rainbowBean);
        }
    }
}
